﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.BLL
{
    public class RetirementDetailBLL : IRetirementDetailBLL
    {
        private static readonly IRetirementDetailDAL DAL = DataAccess.CreateRetirementDetails();

        private RetirementDetailInfo Info = new RetirementDetailInfo();
        private RetirementInfo pInfo = new RetirementInfo();
        private EmployeeInfo empInfo = new EmployeeInfo();

        public DataSet LoadRetirementDetails(Nullable<int> Sequence, Nullable<int> RetirementSeq)
        {
            Info.Sequence = Sequence.HasValue ? (int)Sequence : 0;

            if (RetirementSeq.HasValue)
            {
                pInfo.Sequence = (int)RetirementSeq;
                Info.Parent = pInfo;
            }

            return DAL.LoadRetirementDetails(Info);
        }

        public void Insert(int Parent, string Employee, string Remarks, int CreatedBy)
        {
            pInfo.Sequence = Parent;

            if (Employee.Length > 0)
                empInfo.Sequence = Int32.Parse(Employee);
            try
            {
                DAL.Insert(new RetirementDetailInfo(0, pInfo, empInfo, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, int Parent, string Employee, string Remarks, int UpdatedBy)
        {
            pInfo.Sequence = Parent;

            if (Employee.Length > 0)
                empInfo.Sequence = Int32.Parse(Employee);
            try
            {
                DAL.Update(new RetirementDetailInfo(Sequence, pInfo, empInfo, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
